<template>
    <el-select v-model="selectedVal" :clearable="!form" class="filter-item" placeholder="选择模式方案" style="width: 150px;">
        <el-option label="未选择" :value="0" v-if="form"></el-option>
        <el-option
                v-for="(item, index) in prizePoolModes"
                :key="index"
                :label="item.id + ' ) ' + item.name"
                :value="item.id">
        </el-option>
    </el-select>
</template>

<script>
    export default {
        props: {
            value: {},
            type: {},
            form: {
                type: Boolean,
                default: false,
            }
        },
        data () {
            return {
                selectedVal: '',
            };
        },
        computed: {
            prizePoolModes () {
                if (this.type === undefined) return this.$store.state.prizePoolMode.all;
                return this.$store.state.prizePoolMode.all.filter(v => {
                    return parseInt(this.type) === v.type;
                })
            },
        },
        watch: {
            value() {
                this.syncForm();
            },
            selectedVal() {
                this.$emit('input', this.selectedVal);
            }
        },
        methods: {
            getPrizePoolModes() {
                if (!this.prizePoolModes.length) this.$store.dispatch('prizePoolMode/All', 'prizePoolMode');
            },
            syncForm() {
                this.selectedVal = this.value;
            },
        },
        created() {
            this.getPrizePoolModes();
            this.syncForm();
        }
    }
</script>

<style scoped>

</style>
